# coding=utf-8
from numpy import mat, matrix, shape, multiply


# 上述NumPy中的关键字mat是matrix的缩写

def aprint(str, obj):
    print("----------\n{0}:\n{1}".format(str, obj))


pyList = [5, 11, 1605]
mPyList = mat(pyList)
print "mPyList:{0}".format(mPyList)

ss = mat([1, 2, 3])
print "ss:{0}".format(ss)
mm3 = matrix([[1, 2, 3], [1, 2, 3], [1, 2, 3]])
mm = matrix([1, 2, 3])
print "mm:{0}".format(mm)
print "mm3:{0}".format(mm3)
# .T 横纵交换 转置
print "ss.T:{0}".format(ss.T)
print "mm.T:{0}".format(mm.T)
# print mm*ss  wrong
#向量乘积
print "mm * ss.T:{0}".format(mm * ss.T)
aprint("mm * mm.T", mm * mm.T)

# shape 查看维度
aprint("shape(mm)",shape(mm))
aprint("shape(ss)",shape(ss))

#向量 按元素相乘 点积算一半？没听说过
aprint("multiply(mm,ss)",multiply(mm,ss))

#排序 原地排序，排序后矩阵变为新矩阵，不可逆，如果想保留需要copy
tosortM = mat([[1, 9, 3], [30, 2, 3], [1, 2, 3]])
aprint("before sort tosortM",tosortM)
aprint("tosortM.argsort()",tosortM.argsort())
aprint("tosortM.sort()",tosortM.sort())
aprint("after sort tosortM",tosortM)
#argsort可以返回每个元素从小到大排序后，每个元素原来索引的顺序

dd = mat([4, 5, 1])
aprint("before sort dd",dd)
aprint("dd.argsort()",dd.argsort())


#求均值
aprint("dd.mean()",dd.mean())


jj = matrix([[1,2,3],[8,8,8]])
aprint("jj",jj)
aprint("jj[1]",jj[1])
aprint("jj[1,:]",jj[1,:])
aprint("jj[:,0]",jj[:,0])
#取0行的 从0列往后取，不包含1列
aprint("jj[0,0:1]",jj[0,0:1])

#更多 http://docs.scipy.org/doc/。
